package com.hanrui.android.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hanrui.android.R;
import com.hanrui.android.activity.MainActivity;
import com.hanrui.android.activity.message.AuditActivity;
import com.hanrui.android.activity.message.MeetActivity;
import com.hanrui.android.activity.message.MyPerformanceActivity;
import com.hanrui.android.activity.message.MySuperviseActivity;
import com.hanrui.android.activity.message.ReceiptDocListActivity;
import com.hanrui.android.adapter.MainMessigeAdapter;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.CountBean;
import com.hanrui.android.model.MainMessigeListBean;
import com.hanrui.android.net.contract.message.audit.CountContract;
import com.hanrui.android.net.presenter.message.audit.CountPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


/**
 * 消息
 * Created by zhengwei on 2018/1/31.
 */

public class MessageFragment extends BaseFragment<CountPresenter> implements CountContract.View {

    @BindView(R.id.recyclerview)
    RecyclerView recyclerView;
    MainMessigeAdapter adapter;
    MainActivity mActivity;

    String approveNum;


    @Override
    protected int getLayoutId() {
        return R.layout.recyclerview_base;
    }

    @Override
    protected void initInjector() {mFragmentComponent.inject(this);}

    @Override
    protected void initView(View view) {
        mActivity = (MainActivity) getActivity();
        setRecyclerView();
    }


    //实例化
    public static MessageFragment newInstance() {
        return new MessageFragment();
    }

    @Override
    public void onResume() {
        super.onResume();
        mPresenter.getCountsInfo(mActivity);
    }

    private void setRecyclerView(){

        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        adapter = new MainMessigeAdapter();
        recyclerView.setAdapter(adapter);
        adapter.setNewData(getListData());


        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                switch (position) {
                    case 0:
                        //审批提醒
                        AuditActivity.start(mActivity,0);
                        break;
                    case 1:
                        //我的会议
                        MeetActivity.start(mActivity,0);
                        break;
                    case 4:
                        //我的收文
                        mActivity.openActivity(ReceiptDocListActivity.class);
                        break;
                    case 5:
                        //我的督办
                        MySuperviseActivity.start(mActivity,0);
                        break;
                    case 6:
                        //我的绩效
                        mActivity.openActivity(MyPerformanceActivity.class);
                        break;
                    default:
                        ToastUtils.showShort("开发中...");
                        break;

                		}


            }
        });
    }

    private List<MainMessigeListBean> getListData(){

        List<MainMessigeListBean> list = new ArrayList<>();

        MainMessigeListBean sptx = new MainMessigeListBean();
        sptx.setIcon(R.mipmap.sp2x);
        sptx.setTitle("审批提醒");
        sptx.setNum(approveNum);
        list.add(sptx);

        MainMessigeListBean wdhy = new MainMessigeListBean();
        wdhy.setIcon(R.mipmap.wdhy2x);
        wdhy.setTitle("我的会议");
        list.add(wdhy);

        MainMessigeListBean wdpx = new MainMessigeListBean();
        wdpx.setIcon(R.mipmap.wdpx2x);
        wdpx.setTitle("我的培训");
        list.add(wdpx);

        MainMessigeListBean wdrc = new MainMessigeListBean();
        wdrc.setIcon(R.mipmap.wdrc2x);
        wdrc.setTitle("我的日程");
        list.add(wdrc);

        MainMessigeListBean wdwk = new MainMessigeListBean();
        wdwk.setIcon(R.mipmap.wdwjk2x);
        wdwk.setTitle("收文管理");
        list.add(wdwk);

        MainMessigeListBean wddb = new MainMessigeListBean();
        wddb.setIcon(R.mipmap.wddb2x);
        wddb.setTitle("我的督办");
        list.add(wddb);

        MainMessigeListBean wdjx = new MainMessigeListBean();
        wdjx.setIcon(R.mipmap.wdjx2x);
        wdjx.setTitle("我的绩效");
        list.add(wdjx);

        MainMessigeListBean tzgg = new MainMessigeListBean();
        tzgg.setIcon(R.mipmap.tzgg2x);
        tzgg.setTitle("通知公告");
        list.add(tzgg);

        return list;

    }

    @Override
    public void getCountsInfo(CountBean data) {

        if (data.getActListSize() > 0 && data.getActListSize() <= 99) {

            approveNum = String.valueOf(data.getActListSize());

        		}else if (data.getActListSize() > 99) {

            approveNum = "99+";
        }

        adapter.getItem(0).setNum(approveNum);
        adapter.notifyDataSetChanged();

    }
}
